﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SaleSoft.Models;
using SaleSoft.Helper;

namespace SaleSoft.Areas.administrator.Controllers
{
    public class LoginController : Controller
    {
        private SaleSoftEntities db = new SaleSoftEntities();

        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Index ( string username, string password ) {
            try {
                ds_nhanvienquanly user = db.ds_nhanvienquanly.Single(o => (o.tendangnhap == username && o.matkhau == password));
                if (user == null) {
                    return View();
                } else {
                    SessionHelper.SetUser(user);
                    return RedirectToAction("Index", "Dashboard");
                }
            } catch (Exception) {
                return View();
            }
        }

        public ActionResult Logout () {
            SessionHelper.ClearUser();
            return RedirectToAction("Index", "Login");
        }
    }
}
